package fun.pengzh.demo.kafka.sample2;

import fun.pengzh.demo.kafka.pojo.Foo1;
import org.springframework.core.task.SimpleAsyncTaskExecutor;
import org.springframework.core.task.TaskExecutor;
import org.springframework.kafka.annotation.KafkaHandler;
import org.springframework.kafka.annotation.KafkaListener;
import org.springframework.stereotype.Component;

/**
 * @author pengzh
 * @class MutilMethod
 * @since 2021-09-14
 */
@Component
@KafkaListener(groupId = "mutiGroup", topics = {"foos", "bars"})
public class MutilMethod {

    private final TaskExecutor executor = new SimpleAsyncTaskExecutor();

    public void terminate() {
        executor.execute(() -> {
            System.out.println("Hit ther Enter to terminate。。。");
        });
    }

    @KafkaHandler
    public void foos(Foo1 foo) {
        System.out.println("Received: " + foo);
        terminate();
    }

    @KafkaHandler
    public void bars(Foo1 foo) {
        System.out.println("Received: " + foo);
        terminate();
    }

    @KafkaHandler(isDefault = true)
    public void unknown(Object object) {
        System.out.println("Received unknown: " + object);
        terminate();
    }
}
